﻿using OpenTK.Input;
using OpenTK;
using System;

namespace Painter3D.Tool
{
    [Obsolete]
    class CameraControl : Component
    {
        public float lineSpeed;
        public float angleSpeed;

        private int lastMousePosX;
        private int lastMousePosY;
        private float pitch = 0.0f;
        private float yaw = 0.0f;
        private float roll = 0.0f;

        public CameraControl(float lineSpeed, float angleSpeed, Transform transform) : base(transform)
        {
            this.lineSpeed = lineSpeed;
            this.angleSpeed = angleSpeed;
        }

        protected override void Loop()
        {
            if (InputManager.keyboard.IsKeyDown(Key.W))
            {
                transform.Translate(Vector3.UnitZ * InputManager.timeStep * -lineSpeed);
            }
            else if (InputManager.keyboard.IsKeyDown(Key.S))
            {
                transform.Translate(Vector3.UnitZ * InputManager.timeStep * lineSpeed);
            }
            else if (InputManager.keyboard.IsKeyDown(Key.A))
            {
                transform.Translate(Vector3.UnitX * InputManager.timeStep * -lineSpeed);
            }
            else if (InputManager.keyboard.IsKeyDown(Key.D))
            {
                transform.Translate(Vector3.UnitX * InputManager.timeStep * lineSpeed);
            }

            if (InputManager.mouse.IsButtonDown(MouseButton.Right))
            {
                int diffX = InputManager.mouse.X - lastMousePosX;
                int diffY = InputManager.mouse.Y - lastMousePosY;
                pitch += diffY * InputManager.timeStep * angleSpeed;
                yaw += diffX * InputManager.timeStep * angleSpeed;
                transform.quaternion = Quaternion.FromEulerAngles(pitch, yaw, roll);
            }
            lastMousePosX = InputManager.mouse.X;
            lastMousePosY = InputManager.mouse.Y;
        }
    }
}
